package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.PageDomain;
import com.zzyl.nursing.dto.FamilyMemberElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.service.impl.DeviceDataServiceImpl;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private IFamilyMemberElderService familyMemberElderService;
    @Autowired
    private DeviceDataServiceImpl deviceDataServiceImpl;

    @PostMapping("/login")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo vo = familyMemberService.login(dto);
        return success(vo);
    }

    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult add(@RequestBody FamilyMemberElderDto dto){
        familyMemberElderService.add(dto);
        return AjaxResult.success();
    }

    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public AjaxResult findFamilyMemberList() {
        List<FamilyMemberEldVo> familyMemberEldVoList = familyMemberElderService.findFamilyMemberList();
        return AjaxResult.success(familyMemberEldVoList);
    }

    @GetMapping("/list-by-page")
    @ApiOperation("查询家人列表（分页查询）")
    public AjaxResult listByPage(PageDomain pageDomain) {
        startPage();
        List<FamilyListVo> list = familyMemberElderService.listByPage(pageDomain);
        return AjaxResult.success(list);
    }

    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询健康数据")
    public AjaxResult queryServiceProperties(@PathVariable("iotId") String iotId) {
        List<HealthMsgVo> list=familyMemberElderService.queryServiceProperties(iotId);
        return AjaxResult.success(list);
    }


    @Autowired
    private DeviceDataServiceImpl deviceDataService;
    /**
     * 1.5 按天统计查询指标数据
     * 接口地址:/member/user/queryDeviceDataListByDay
     * 请求方式:GET
     */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public AjaxResult queryDeviceDataListByDay(Long startTime, Long endTime, String iotId, String functionId) {
        List<DeviceDataGraphVo> deviceDataGraphvos = deviceDataService.queryDeviceDataListByDay(startTime, endTime, iotId, functionId);
        return AjaxResult.success(deviceDataGraphvos);
    }
/**
 * 按周统计查询指标数据
 * @param startTime
 * @param endTime
 * @param iotId
 * @param functionId
 * @return
 */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public R<List<DeviceDataGraphVo>>queryDeviceDataListByWeek(@RequestParam(value = "startTime", required = true) Long startTime,
                                                               @RequestParam(value = "endTime", required = true) Long endTime,
                                                               @RequestParam(value = "iotId", required = true) String iotId,
                                                               @RequestParam(value = "functionId", required = true) String functionId){
        List<DeviceDataGraphVo>list=deviceDataService.queryDeviceDataListByWeek(startTime,endTime,iotId,functionId);
        return R.ok(list);
    }
}
